package batch.home;

import javax.xml.parsers.*;
import org.xml.sax.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import java.util.Date;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.*;

import java.util.Vector;
import java.util.Properties;
import java.io.*;
import java.net.*;

import batch.common.db.*;
import batch.common.report.*;

public class makeHomeForPol
{
    private final int    ILENG          = 5;
    private final int    ILENG2         = 4;
    private final int    CNT_RINGTONE   = 5;
    private final int    CNT_IMAGE      = 2;
    private final int    CNT_JAVAGAME   = 2;
    private final int    CNT_ONLINEGAME = 4;

    private final String TODAY         = DateFormatUtils.format(new Date(), "yyyyMMdd");  //Get Current Date
    private final String IMAGE_URL     = "/images/main/";
    private final String FILE_PATH     = "/home01/sfc/batch/home/data/pol_home/" + TODAY;
    private final String MAILSUBJECT   = "POL HOME Batch Error(" + TODAY + ")";

    private final String GO_RINGTONES  = "javascript:goMenu('funclub','musictones','poly');";
    private final String RINGTONE_PATH = "/link/goPremium.jsp?menu=musictones&mcate_cd=A2&content_id=";

    private final String GO_IMAGES     = "javascript:goMenu('funclub','graphics','wallpapers');";
    private final String IMAGE_PATH    = "/link/goPremium.jsp?menu=graphics&mcate_cd=08&content_id=";

    private final String GO_JAVAGAMES  = "javascript:goMenu('funclub','games','mobile');";
    private final String JAVAGAME_PATH = "/link/goPremium.jsp?menu=games&mcate_cd=04&content_id=";

    private StringBuffer sHtml = new StringBuffer();

    public makeHomeForPol(){
        init();
    }

    public static void main( String[] args ){
        Logger.getLogger("home.pol_home").info("( * ) Start.");

        makeHomeForPol obj = new makeHomeForPol();

        Logger.getLogger("home.pol_home").info("( * ) End.");
    }

    public void init(){
        BufferedReader bfrString = null;
        ByteArrayInputStream is = null;
        StringBuffer sbfXml = new StringBuffer();

        Document doc = null;
        NodeList nlTemp = null;

        try{
            //For Home page
            //HTTP Connection + ILENG
            URLConnection urlCon = new URL("http://www.sfctest.mobista.pl/sfc/xml/GetAllContentList.do?NUM="+ILENG).openConnection();

            bfrString = new BufferedReader(new InputStreamReader(urlCon.getInputStream(), "UTF-8"));

            String line = "";
            Vector vtElem      = new Vector();
            Vector vRingtone   = new Vector();
            Vector vWallpapers = new Vector();
            Vector vGames      = new Vector();

            while ((line = bfrString.readLine()) != null)
            {
                sbfXml.append(line);
                //Logger.getLogger("home.pol_home").info(line);
            }

            byte bxml[] = sbfXml.toString().getBytes("UTF-8");
            is = new ByteArrayInputStream(bxml);

            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            doc = docBuilder.parse(new InputSource(is));
            Element elem = doc.getDocumentElement();
            elem.normalize();

            nlTemp = elem.getChildNodes();

            for(int x=0;x<nlTemp.getLength();x++){
                if(nlTemp.item(x).getChildNodes().getLength() > 0){
                    vtElem.addElement(nlTemp.item(x).getChildNodes());
                }
            }

            for(int x=0;x<vtElem.size();x++){
                Element tmpElem = (Element)vtElem.elementAt(x);
                String strElem = tmpElem.getTagName();


                for (int i = 0; i < ILENG; i++) {
                    Properties pptNode = new Properties();

                    nlTemp = tmpElem.getElementsByTagName("CONTENT_ID");
                    pptNode.setProperty("CONTENT_ID", nlTemp.item(i).getFirstChild().getNodeValue());
                    nlTemp = tmpElem.getElementsByTagName("CONTENT_NAME");
                    pptNode.setProperty("CONTENT_NAME", nlTemp.item(i).getFirstChild().getNodeValue());
                    nlTemp = tmpElem.getElementsByTagName("PREVIEW_URL");
                    pptNode.setProperty("PREVIEW_URL", nlTemp.item(i).getFirstChild().getNodeValue());

                    if(strElem.equals("GAMES")){
                        vGames.addElement(pptNode);
                    }
                    else if(strElem.equals("RINGTONES")){
                        vRingtone.addElement(pptNode);
                    }
                    else if(strElem.equals("WALLPAPERS")){
                        vWallpapers.addElement(pptNode);
                    }
              }
            }

            File fl = new File(FILE_PATH);

            if(!fl.isDirectory()){
                fl.mkdirs();
            }

            if(vRingtone.size() > 0){
                this.getRingtones(vRingtone);
            }

            if(vWallpapers.size() > 0){
                this.getImages(vWallpapers);
            }

            if(vGames.size() > 0){
                this.getJavaGames(vGames);
            }

            //For Online game pages.
            urlCon = new URL("http://funclub.pl.samsungmobile.com/sfc/xml/GetAllContentList.do?CATEGORY_ID=20229&MALL_ID=04&NUM=4").openConnection();

            bfrString = new BufferedReader(new InputStreamReader(urlCon.getInputStream(), "UTF-8"));

            vtElem.clear();
            vGames.clear();
            sbfXml.setLength(0);
            line  = "";

            while ((line = bfrString.readLine()) != null)
            {
                sbfXml.append(line);
                //Logger.getLogger("home.pol_home").info(line);
            }

            bxml = sbfXml.toString().getBytes("UTF-8");
            is = new ByteArrayInputStream(bxml);

            docBuilderFactory = DocumentBuilderFactory.newInstance();
            docBuilder = docBuilderFactory.newDocumentBuilder();
            doc = docBuilder.parse(new InputSource(is));
            elem = doc.getDocumentElement();
            elem.normalize();

            nlTemp = elem.getChildNodes();

            for(int x=0;x<nlTemp.getLength();x++){
                if(nlTemp.item(x).getChildNodes().getLength() > 0){
                    vtElem.addElement(nlTemp.item(x).getChildNodes());
                }
            }

            for(int x=0;x<vtElem.size();x++){
                Element tmpElem = (Element)vtElem.elementAt(x);
                String strElem = tmpElem.getTagName();


                for (int i = 0; i < ILENG2; i++) {
                    Properties pptNode = new Properties();

                    nlTemp = tmpElem.getElementsByTagName("CONTENT_ID");
                    pptNode.setProperty("CONTENT_ID", nlTemp.item(i).getFirstChild().getNodeValue());
                    nlTemp = tmpElem.getElementsByTagName("CONTENT_NAME");
                    pptNode.setProperty("CONTENT_NAME", nlTemp.item(i).getFirstChild().getNodeValue());
                    nlTemp = tmpElem.getElementsByTagName("PREVIEW_URL");
                    pptNode.setProperty("PREVIEW_URL", nlTemp.item(i).getFirstChild().getNodeValue());
                    nlTemp = tmpElem.getElementsByTagName("ORDER_URL");
                    pptNode.setProperty("ORDER_URL", nlTemp.item(i).getFirstChild().getNodeValue());

                    if(strElem.equals("GAMES")){
                        vGames.addElement(pptNode);
                    }
              }
            }

            if(vGames.size() > 0){
                this.getOnlineGames(vGames);
            }
        }
        catch(Exception ex){
            ex.printStackTrace();
            Logger.getLogger("home.pol_home").info(ex.toString());
            //ReportError.byEmail(MAILSUBJECT, ex.toString());
        }
        finally {
            if (is != null) try { is.close(); } catch (Exception ex) {}
            if (bfrString != null) try { bfrString.close(); } catch (Exception ex) {}
        }
    }


    //Make Ringtone File
    public void getRingtones(Vector pVector) throws Exception {
        OutputStreamWriter fw = null;

        String sContentNM = "";
        String sUrl = "";

        sHtml.setLength(0);

        try{
            sHtml.append("<table width=191 cellpadding=0 cellspacing=0>                                                                                     \n")
                 .append("    <tr>                                                                                                                          \n")
                 .append("        <td height=29 style='background-image : url(" + IMAGE_URL + "bg_box02_01.gif)' align=center>                              \n")
                 .append("            <table width=170 cellpadding=0 cellspacing=0>                                                                         \n")
                 .append("                <tr>                                                                                                              \n")
                 .append("                    <td><a href=" + GO_RINGTONES + "><img src='" + IMAGE_URL + "title_ringtones.gif' align=absmiddle></a></td>    \n")
                 .append("                    <td width=36><a href=" + GO_RINGTONES + "><img src='" + IMAGE_URL + "bn_more01.gif' align=absmiddle></a></td> \n")
                 .append("                </tr>                                                                                                             \n")
                 .append("            </table>                                                                                                              \n")
                 .append("        </td>                                                                                                                     \n")
                 .append("    </tr>                                                                                                                         \n")
                 .append("    <tr>                                                                                                                          \n")
                 .append("        <td height=114 style='background-image : url(" + IMAGE_URL + "bg_box02_02.gif);padding:5 0 0 0' align=center valign=top>  \n")
                 .append("            <table width=183 cellpadding=0 cellspacing=0>                                                                         \n")
                 .append("                <col width=8>                                                                                                     \n")
                 .append("                <col width=160>                                                                                                   \n")
                 .append("                <col width=10>                                                                                                    \n")
                 .append("                <col width=5>                                                                                                     \n");

            for(int i=0; i < CNT_RINGTONE; i++) {
                Properties pContents = (Properties) pVector.elementAt(i);

                sContentNM = StringUtils.defaultString(pContents.getProperty("CONTENT_NAME"));
                if(sContentNM.length() > 20){
                    sContentNM = sContentNM.substring(0, 20) + "..";
                }

                sUrl = RINGTONE_PATH + pContents.getProperty("CONTENT_ID");

                sHtml.append("            <tr bgcolor=#F7FEFF>                                                                                              \n")
                     .append("                <td><img src='" + IMAGE_URL + "bg_box02_03.gif' align=absmiddle></td>                                         \n")
                     .append("                <td><a href='" + sUrl + "' >" + sContentNM + "</a></td>                                              \n")
                     .append("                <td><a href='" + sUrl + "' ><img src='" + IMAGE_URL + "bn_sound.gif' align=absmiddle></a></td>       \n")
                     .append("                <td align=right><img src='" + IMAGE_URL + "bg_box02_04.gif' align=absmiddle></td>                             \n")
                     .append("            </tr>                                                                                                             \n");


                if ( i < (CNT_RINGTONE - 1) ) {
                    sHtml.append("        <tr><td colspan=4 height=1></td></tr>                                                                             \n");
                }

            }

            sHtml.append("            </table>                                                                                                              \n")
                 .append("        </td>                                                                                                                     \n")
                 .append("    </tr>                                                                                                                         \n")
                 .append("</table>                                                                                                                          \n");

            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH + "/ringtone_include.html", false), "UTF-8");
            fw.write(sHtml.toString());

        }
        finally{
            if (fw != null) try { fw.close(); } catch (Exception e) {}
        }
    }

    //Make Images File
    public void getImages(Vector pVector) throws Exception {
        OutputStreamWriter fw = null;

        String[][] asContents = new String[CNT_IMAGE][3];

        sHtml.setLength(0);

        try{
            for(int i=0; i<asContents.length; i++) {
                Properties pContents = (Properties) pVector.elementAt(i);

                asContents[i][0] = StringUtils.defaultString(pContents.getProperty("CONTENT_NAME"));
                if(asContents[i][0].length() > 12){
                    asContents[i][0] = asContents[i][0].substring(0, 12) + "..";
                }

                asContents[i][1] = pContents.getProperty("PREVIEW_URL");
                asContents[i][2] = IMAGE_PATH + pContents.getProperty("CONTENT_ID");
            }

            sHtml.append("<table width=191 cellpadding=0 cellspacing=0>                                                                                                                                               \n")
                 .append("    <tr height=29>                                                                                                                                                                          \n")
                 .append("        <td style='background-image : url(" + IMAGE_URL + "bg_title_02.gif)' align=center >                                                                                                 \n")
                 .append("            <table width=170 cellpadding=0 cellspacing=0>                                                                                                                                   \n")
                 .append("                <tr>                                                                                                                                                                        \n")
                 .append("                    <td><a href=" + GO_IMAGES + "><img src='" + IMAGE_URL + "title_screensavers.gif' align=absmiddle></a></td>                                                              \n")
                 .append("                    <td width=36><a href=" + GO_IMAGES + "><img src='" + IMAGE_URL + "bn_more03.gif' align=absmiddle></a></td>                                                              \n")
                 .append("                </tr>                                                                                                                                                                       \n")
                 .append("            </table>                                                                                                                                                                        \n")
                 .append("        </td>                                                                                                                                                                               \n")
                 .append("    </tr>                                                                                                                                                                                   \n")
                 .append("    <tr><td height=2></td></tr>                                                                                                                                                             \n")
                 .append("    <tr>                                                                                                                                                                                    \n")
                 .append("        <td height=112 style='background-image : url(" + IMAGE_URL + "bg_box03.gif);padding:13 0 0 0' align=center valign=top>                                                              \n")
                 .append("            <table width=166 cellpadding=0 cellspacing=0>                                                                                                                                   \n")
                 .append("                <tr>                                                                                                                                                                        \n")
                 .append("                    <td>                                                                                                                                                                    \n")
                 .append("                        <table width=79 height=79 cellpadding=1 cellspacing=0 bgcolor=#9AA9B4>                                                                                              \n")
                 .append("                            <tr>                                                                                                                                                            \n")
                 .append("                                <td><a href=" + asContents[0][2] + "><img src='" + asContents[0][1] + "' width=77 height=77 align=absmiddle></a></td>                                       \n")
                 .append("                            </tr>                                                                                                                                                           \n")
                 .append("                        </table>                                                                                                                                                            \n")
                 .append("                    </td>                                                                                                                                                                   \n")
                 .append("                    <td width=8></td>                                                                                                                                                       \n")
                 .append("                    <td>                                                                                                                                                                    \n")
                 .append("                        <table width=79 height=79 cellpadding=1 cellspacing=0 bgcolor=#9AA9B4>                                                                                              \n")
                 .append("                            <tr>                                                                                                                                                            \n")
                 .append("                                <td><a href=" + asContents[1][2] + "><img src='" + asContents[1][1] + "' width=77 height=77 align=absmiddle></a></td>                                       \n")
                 .append("                            </tr>                                                                                                                                                           \n")
                 .append("                        </table>                                                                                                                                                            \n")
                 .append("                    </td>                                                                                                                                                                   \n")
                 .append("                </tr>                                                                                                                                                                       \n")
                 .append("            </table>                                                                                                                                                                        \n")
                 .append("        </td>                                                                                                                                                                               \n")
                 .append("    </tr>                                                                                                                                                                                   \n")
                 .append("</table>                                                                                                                                                                                    \n");

            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH + "/image_include.html", false), "UTF-8");
            fw.write(sHtml.toString());

        }
        finally{
            if (fw != null) try { fw.close(); } catch (Exception e) {}
        }
    }


    //Make JavaGames File
    public void getJavaGames(Vector pVector) throws Exception {

        OutputStreamWriter fw = null;

        String[][] asContents = new String[CNT_JAVAGAME][3];

        sHtml.setLength(0);

        try{
            for(int i=0; i<asContents.length; i++) {
                Properties pContents = (Properties) pVector.elementAt(i);

                asContents[i][0] = StringUtils.defaultString(pContents.getProperty("CONTENT_NAME"));
                if(asContents[i][0].length() > 12){
                    asContents[i][0] = asContents[i][0].substring(0, 12) + "..";
                }

                asContents[i][1] = pContents.getProperty("PREVIEW_URL");
                asContents[i][2] = JAVAGAME_PATH + pContents.getProperty("CONTENT_ID");
            }

            sHtml.append("<table width=191 cellpadding=0 cellspacing=0>                                                                                                                                               \n")
                 .append("    <tr height=29>                                                                                                                                                                          \n")
                 .append("        <td style='background-image : url(" + IMAGE_URL + "bg_title_01.gif)' align=center >                                                                                                 \n")
                 .append("            <table width=170 cellpadding=0 cellspacing=0>                                                                                                                                   \n")
                 .append("                <tr>                                                                                                                                                                        \n")
                 .append("                    <td><a href=" + GO_JAVAGAMES + "><img src='" + IMAGE_URL + "title_mobile_games.gif' align=absmiddle></a></td>                                                           \n")
                 .append("                    <td width=36><a href=" + GO_JAVAGAMES + "><img src='" + IMAGE_URL + "bn_more02.gif' align=absmiddle></a></td>                                                           \n")
                 .append("                </tr>                                                                                                                                                                       \n")
                 .append("            </table>                                                                                                                                                                        \n")
                 .append("        </td>                                                                                                                                                                               \n")
                 .append("    </tr>                                                                                                                                                                                   \n")
                 .append("    <tr><td height=2></td></tr>                                                                                                                                                             \n")
                 .append("    <tr>                                                                                                                                                                                    \n")
                 .append("        <td height=112 style='background-image : url(" + IMAGE_URL + "bg_box03.gif);padding:13 0 0 0' align=center valign=top>                                                              \n")
                 .append("            <table width=166 cellpadding=0 cellspacing=0>                                                                                                                                   \n")
                 .append("                <tr>                                                                                                                                                                        \n")
                 .append("                    <td>                                                                                                                                                                    \n")
                 .append("                        <table width=79 height=79 cellpadding=1 cellspacing=0 bgcolor=#9AA9B4>                                                                                              \n")
                 .append("                            <tr>                                                                                                                                                            \n")
                 .append("                                <td><a href=" + asContents[0][2] + "><img src='" + asContents[0][1] + "' width=77 height=77 align=absmiddle></a></td>                                       \n")
                 .append("                            </tr>                                                                                                                                                           \n")
                 .append("                        </table>                                                                                                                                                            \n")
                 .append("                    </td>                                                                                                                                                                   \n")
                 .append("                    <td width=8></td>                                                                                                                                                       \n")
                 .append("                    <td>                                                                                                                                                                    \n")
                 .append("                        <table width=79 height=79 cellpadding=1 cellspacing=0 bgcolor=#9AA9B4>                                                                                              \n")
                 .append("                            <tr>                                                                                                                                                            \n")
                 .append("                                <td><a href=" + asContents[1][2] + "><img src='" + asContents[1][1] + "' width=77 height=77 align=absmiddle></a></td>                                       \n")
                 .append("                            </tr>                                                                                                                                                           \n")
                 .append("                        </table>                                                                                                                                                            \n")
                 .append("                    </td>                                                                                                                                                                   \n")
                 .append("                </tr>                                                                                                                                                                       \n")
                 .append("                <tr>                                                                                                                                                                        \n")
                 .append("                    <td class=f_09 style='padding:3 0 0 0'><img src='" + IMAGE_URL + "icon_02.gif' align=absmiddle>&nbsp;<a href=" + asContents[0][2] + ">" + asContents[0][0] + "</a></td> \n")
                 .append("                    <td></td>                                                                                                                                                               \n")
                 .append("                    <td class=f_09 style='padding:3 0 0 0'><img src='" + IMAGE_URL + "icon_02.gif' align=absmiddle>&nbsp;<a href=" + asContents[1][2] + ">" + asContents[1][0] + "</a></td> \n")
                 .append("                </tr>                                                                                                                                                                       \n")
                 .append("            </table>                                                                                                                                                                        \n")
                 .append("        </td>                                                                                                                                                                               \n")
                 .append("    </tr>                                                                                                                                                                                   \n")
                 .append("</table>                                                                                                                                                                                    \n");

            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH + "/javagame_include.html", false), "UTF-8");
            fw.write(sHtml.toString());

        }
        finally{
            if (fw != null) try { fw.close(); } catch (Exception e) {}
        }
    }


    //Make OnlineGame File
    public void getOnlineGames(Vector pVector) throws Exception {

        OutputStreamWriter fw = null;

        String sCttId    = "";
        String sCttName  = "";
        String sPreUrl   = "";
        String sOrderUrl = "";
        String sMoreInfo = "";
       
        sHtml.setLength(0);

        try{
            sHtml.append("<table width=200 cellpadding=0 cellspacing=0>                                                                 \n")
                 .append(" <tr>                                                                                                         \n")
                 .append("     <td>                                                                                                     \n")
                 .append("         <table width=200 cellpadding=0 cellspacing=0>                                                        \n")
                 .append("             <tr height=43>                                                                                   \n")
                 .append("                 <td style=\"background:url(/images/funclub/game/bg_box04_01.gif) no-repeat;\" align=center>  \n")
                 .append("                     <table width=190 cellpadding=0 cellspacing=0 class=fixed>                                \n")
                 .append("                         <tr>                                                                                 \n")
                 .append("                             <td width=120 style=\"padding:3 0 0 10;\" class=f_18_ff>                         \n")
                 .append("                                  <a href=\"http://funclub.pl.samsungmobile.com/sfc/games.do?cT=J&cId=20229\">\n")
                 .append("                                     <img src=\"/images/funclub/game/title_topseller.gif\" align=absmiddle>   \n")
                 .append("                                  </a>                                                                        \n")
                 .append("                             </td>                                                                            \n")
                 .append("                             <td align=right>                                                                 \n")
                 .append("                                 <a href=\"http://funclub.pl.samsungmobile.com/sfc/games.do?cT=J&cId=20229\"> \n")
                 .append("                                     <img src=\"/images/funclub/game/bn_more4.gif\" align=absmiddle>          \n")
                 .append("                                 </a>                                                                         \n")
                 .append("                             </td>                                                                            \n")
                 .append("                         </tr>                                                                                \n")
                 .append("                     </table>                                                                                 \n")
                 .append("                 </td>                                                                                        \n")
                 .append("             </tr>                                                                                            \n")
                 .append("             <tr height=10><td bgcolor=#6BBDF1></td></tr>                                                     \n")
                 .append("             <tr>                                                                                             \n")
                 .append("                 <td bgcolor=#6BBDF1 align=center>                                                            \n")
                 .append("                     <table width=176 cellpadding=0 cellspacing=0 class=fixed id=Games_list>                  \n")
                 .append("                         <tr>                                                                                 \n")
                 .append("                             <td>                                                                             \n")
                 .append("                                 <table width=176 cellpadding=0 cellspacing=0 style=\"margin:4 0 4 0;\">      \n");


            for(int i=0; i<CNT_ONLINEGAME; i++) {
                Properties pContents = (Properties) pVector.elementAt(i);

                sCttName  = StringUtils.defaultString(pContents.getProperty("CONTENT_NAME"));
                sPreUrl   = StringUtils.defaultString(pContents.getProperty("PREVIEW_URL"));
                sCttId    = StringUtils.defaultString(pContents.getProperty("CONTENT_ID"));
                sMoreInfo = "http://funclub.pl.samsungmobile.com/sfc/gameDetails.do?cT=J&c=1&contentId=" + sCttId +"&cId=20229&r=4&page=1";
                //sOrderUrl = StringUtils.defaultString(pContents.getProperty("ORDER_URL"));                
                sOrderUrl = "http://funclub.pl.samsungmobile.com/sfc/order.do?contentId=" + sCttId +"&cId=20229&cT=J&c=1&r=4&page=1";


                sHtml.append("                                <tr>                                                                                                                                                                                                                      \n")
                     .append("                                  <td width=88><a href=\"" + sMoreInfo + "\" onFocus=\"this.blur()\"><img src=\"" + sPreUrl + "\" align=absmiddle class=border_01 width=77 height=77></a></td>                               \n")
                     .append("                                  <td valign=top>                                                                                                                                                                                                         \n")
                     .append("                                      <table cellpadding=0 cellspacing=0 style=\"margin:6 0 4 0;\">                                                                                                                                                       \n")
                     .append("                                          <tr height=32 valign=top><td width=88><a href=\"" + sMoreInfo + "\" onFocus=\"this.blur()\" class=f_11_ff><b>" + sCttName + "</b></a><br></td></tr>                                \n")
                     .append("                                          <tr height=17>                                                                                                                                                                                                  \n")
                     .append("                                              <td width=88>                                                                                                                                                                                               \n")
                     .append("                                                  <a href=\"" + sMoreInfo + "\" onFocus=\"this.blur()\"><img src=\"/images/funclub/game/bn_moreinfo_2.gif\" align=absmiddle style=\"margin:5 0 0 0;\" alt=\"More Info\"></a> \n")
                     .append("                                              </td>                                                                                                                                                                                                       \n")
                     .append("                                          </tr>                                                                                                                                                                                                           \n")
                     .append("                                          <tr height=2><td width=\"88\"></td></tr>                                                                                                                                                                        \n")
                     .append("                                          <tr height=17>                                                                                                                                                                                                  \n")
                     .append("                                              <td width=\"88\">                                                                                                                                                                                           \n")
                     .append("                                                <a href=\"#\" onclick=\"javascript:window.open('" + sOrderUrl + "','SFC','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width=600,height=480');\">           \n")
                     .append("                                                    <img src=\"/images/funclub/game/bn_buy.gif\" alt=\"\" width=\"58\" height=\"15\" border=\"0\" align=\"absmiddle\">                                                                                    \n")
                     .append("                                                </a>                                                                                                                                                                                                      \n")
                     .append("                                              </td>                                                                                                                                                                                                       \n")
                     .append("                                          </tr>                                                                                                                                                                                                           \n")
                     .append("                                          <tr><td width=\"88\"></td></tr>                                                                                                                                                                                 \n")
                     .append("                                      </table>                                                                                                                                                                                                            \n")
                     .append("                                  </td>                                                                                                                                                                                                                   \n")
                     .append("                              </tr>                                                                                                                                                                                                                       \n");
            }

            sHtml.append("                                  </table>                                                           \n")
                 .append("                                                                                                     \n")
                 .append("                                </td>                                                                \n")
                 .append("                            </tr>                                                                    \n")
                 .append("                        </table>                                                                     \n")
                 .append("                    </td>                                                                            \n")
                 .append("                </tr>                                                                                \n")
                 .append("                <tr><td><img src=\"/images/funclub/game/bg_box03_03.gif\" align=absmiddle></td></tr> \n")
                 .append("            </table>                                                                                 \n")
                 .append("        </td>                                                                                        \n")
                 .append("    </tr>                                                                                            \n")
                 .append("</table>                                                                                             \n");

            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH + "/onlinegame_include.html", false), "UTF-8");
            fw.write(sHtml.toString());

        }
        finally{
            if (fw != null) try { fw.close(); } catch (Exception e) {}
        }
    }
}